{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 1: Computing with Python"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Robert Johansson\n",
    "\n",
    "Source code listings for [Numerical Python - Scientific Computing and Data Science Applications with Numpy, SciPy and Matplotlib](https://www.apress.com/us/book/9781484242452) (ISBN 978-1-484242-45-2)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Interpreter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Overwriting hello.py\n"
     ]
    }
   ],
   "source": [
    "%%writefile hello.py\n",
    "print(\"Hello from Python!\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello from Python!\n"
     ]
    }
   ],
   "source": [
    "!python hello.py"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Python 3.7.3\n"
     ]
    }
   ],
   "source": [
    "!python --version"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Input and output caching"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "3 * 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'3 * 3'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "In[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Out[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['', '3 * 3', 'In[1]', 'Out[1]', 'In']"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "In"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1: 9, 2: '3 * 3', 3: 9, 4: ['', '3 * 3', 'In[1]', 'Out[1]', 'In', 'Out']}"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Out"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1+2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "1+2;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "x = 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = 2; x"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Documentation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "# try os.w<TAB>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "import math"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\u001b[0;31mDocstring:\u001b[0m\n",
       "cos(x)\n",
       "\n",
       "Return the cosine of x (measured in radians).\n",
       "\u001b[0;31mType:\u001b[0m      builtin_function_or_method\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "math.cos?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Interaction with System Shell"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "!touch file1.py file2.py file3.py"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "file1.py file2.py file3.py\n"
     ]
    }
   ],
   "source": [
    "!ls file*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "files = !ls file*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(files)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['file1.py', 'file2.py', 'file3.py']"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "files"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "file = \"file1.py\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-rw-r--r--  1 rob  staff  0 May  6 12:30 file1.py\n"
     ]
    }
   ],
   "source": [
    "!ls -l $file"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Running scripts from the IPython console"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Overwriting fib.py\n"
     ]
    }
   ],
   "source": [
    "%%writefile fib.py\n",
    "\n",
    "def fib(N): \n",
    "    \"\"\" \n",
    "    Return a list of the first N Fibonacci numbers.\n",
    "    \"\"\" \n",
    "    f0, f1 = 0, 1\n",
    "    f = [1] * N\n",
    "    for n in range(1, N):\n",
    "        f[n] = f0 + f1\n",
    "        f0, f1 = f1, f[n]\n",
    "\n",
    "    return f\n",
    "\n",
    "print(fib(10))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 1, 2, 3, 5, 8, 13, 21, 34, 55]\n"
     ]
    }
   ],
   "source": [
    "!python fib.py"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 1, 2, 3, 5, 8, 13, 21, 34, 55]\n"
     ]
    }
   ],
   "source": [
    "%run fib.py"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 1, 2, 3, 5, 8]"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fib(6)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Debugger"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "can't multiply sequence by non-int of type 'float'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-25-da4664af34ee>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mfib\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1.0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;32m~/Desktop/numerical-python-apress-revision/numerical-python-book-code/fib.py\u001b[0m in \u001b[0;36mfib\u001b[0;34m(N)\u001b[0m\n\u001b[1;32m      5\u001b[0m     \"\"\" \n\u001b[1;32m      6\u001b[0m     \u001b[0mf0\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mf1\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 7\u001b[0;31m     \u001b[0mf\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0mN\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      8\u001b[0m     \u001b[0;32mfor\u001b[0m \u001b[0mn\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mN\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      9\u001b[0m         \u001b[0mf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mn\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mf0\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mf1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mTypeError\u001b[0m: can't multiply sequence by non-int of type 'float'"
     ]
    }
   ],
   "source": [
    "fib(1.0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "> \u001b[0;32m/Users/rob/Desktop/numerical-python-apress-revision/numerical-python-book-code/fib.py\u001b[0m(7)\u001b[0;36mfib\u001b[0;34m()\u001b[0m\n",
      "\u001b[0;32m      5 \u001b[0;31m    \"\"\" \n",
      "\u001b[0m\u001b[0;32m      6 \u001b[0;31m    \u001b[0mf0\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mf1\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0m\u001b[0;32m----> 7 \u001b[0;31m    \u001b[0mf\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0mN\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0m\u001b[0;32m      8 \u001b[0;31m    \u001b[0;32mfor\u001b[0m \u001b[0mn\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mN\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0m\u001b[0;32m      9 \u001b[0;31m        \u001b[0mf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mn\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mf0\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mf1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0m\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "ipdb>  q\n"
     ]
    }
   ],
   "source": [
    "%debug"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Timing and profiling code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "12.5 µs ± 712 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n"
     ]
    }
   ],
   "source": [
    "%timeit fib(100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 21 µs, sys: 1 µs, total: 22 µs\n",
      "Wall time: 27.2 µs\n"
     ]
    }
   ],
   "source": [
    "result = %time fib(100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "100"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "\n",
    "def random_walker_max_distance(M, N):\n",
    "    \"\"\"\n",
    "    Simulate N random walkers taking M steps, and return the largest distance\n",
    "    from the starting point achieved by any of the random walkers.\n",
    "    \"\"\"\n",
    "    trajectories = [np.random.randn(M).cumsum() for _ in range(N)]\n",
    "    return np.max(np.abs(trajectories))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " "
     ]
    },
    {
     "data": {
      "text/plain": [
       "         20010 function calls in 0.353 seconds\n",
       "\n",
       "   Ordered by: internal time\n",
       "\n",
       "   ncalls  tottime  percall  cumtime  percall filename:lineno(function)\n",
       "    10000    0.194    0.000    0.194    0.000 {method 'randn' of 'mtrand.RandomState' objects}\n",
       "    10000    0.069    0.000    0.069    0.000 {method 'cumsum' of 'numpy.ndarray' objects}\n",
       "        1    0.054    0.054    0.340    0.340 <ipython-input-30-a0ebffe020ed>:3(random_walker_max_distance)\n",
       "        1    0.019    0.019    0.282    0.282 <ipython-input-30-a0ebffe020ed>:8(<listcomp>)\n",
       "        1    0.013    0.013    0.353    0.353 <string>:1(<module>)\n",
       "        1    0.004    0.004    0.004    0.004 {method 'reduce' of 'numpy.ufunc' objects}\n",
       "        1    0.000    0.000    0.004    0.004 fromnumeric.py:69(_wrapreduction)\n",
       "        1    0.000    0.000    0.353    0.353 {built-in method builtins.exec}\n",
       "        1    0.000    0.000    0.004    0.004 fromnumeric.py:2397(amax)\n",
       "        1    0.000    0.000    0.000    0.000 fromnumeric.py:70(<dictcomp>)\n",
       "        1    0.000    0.000    0.000    0.000 {method 'items' of 'dict' objects}\n",
       "        1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%prun random_walker_max_distance(400, 10000)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Jupyter notebook"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "from IPython.display import display, Image, HTML, Math"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<img src=\"http://python.org/images/python-logo.gif\"/>"
      ],
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Image(url='http://python.org/images/python-logo.gif')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "import scipy, numpy, matplotlib\n",
    "modules = [numpy, matplotlib, scipy]\n",
    "row = \"<tr> <td>%s</td> <td>%s</td> </tr>\"\n",
    "rows = \"\\n\".join([row % (module.__name__, module.__version__) for module in modules])\n",
    "s = \"<table> <tr><th>Library</th><th>Version</th> </tr> %s</table>\" % rows"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'<table> <tr><th>Library</th><th>Version</th> </tr> <tr> <td>numpy</td> <td>1.13.3</td> </tr>\\n<tr> <td>matplotlib</td> <td>3.0.0</td> </tr>\\n<tr> <td>scipy</td> <td>1.1.0</td> </tr></table>'"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table> <tr><th>Library</th><th>Version</th> </tr> <tr> <td>numpy</td> <td>1.13.3</td> </tr>\n",
       "<tr> <td>matplotlib</td> <td>3.0.0</td> </tr>\n",
       "<tr> <td>scipy</td> <td>1.1.0</td> </tr></table>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "HTML(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "class HTMLDisplayer(object):\n",
    "    def __init__(self, code):\n",
    "        self.code = code\n",
    "    \n",
    "    def _repr_html_(self):\n",
    "        return self.code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table> <tr><th>Library</th><th>Version</th> </tr> <tr> <td>numpy</td> <td>1.13.3</td> </tr>\n",
       "<tr> <td>matplotlib</td> <td>3.0.0</td> </tr>\n",
       "<tr> <td>scipy</td> <td>1.1.0</td> </tr></table>"
      ],
      "text/plain": [
       "<__main__.HTMLDisplayer at 0x10f83a4e0>"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "HTMLDisplayer(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$\\hat{H} = -\\frac{1}{2}\\epsilon \\hat{\\sigma}_z-\\frac{1}{2}\\delta \\hat{\\sigma}_x$$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Math(r'\\hat{H} = -\\frac{1}{2}\\epsilon \\hat{\\sigma}_z-\\frac{1}{2}\\delta \\hat{\\sigma}_x')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "class QubitHamiltonian(object):\n",
    "    def __init__(self, epsilon, delta):\n",
    "        self.epsilon = epsilon\n",
    "        self.delta = delta\n",
    "\n",
    "    def _repr_latex_(self):\n",
    "        return \"$\\hat{H} = -%.2f\\hat{\\sigma}_z-%.2f\\hat{\\sigma}_x$\" % \\\n",
    "            (self.epsilon/2, self.delta/2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\hat{H} = -0.25\\hat{\\sigma}_z-0.12\\hat{\\sigma}_x$"
      ],
      "text/plain": [
       "<__main__.QubitHamiltonian at 0x10f83a2e8>"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "QubitHamiltonian(0.5, 0.25)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "from scipy import stats\n",
    "\n",
    "def f(mu):\n",
    "    X = stats.norm(loc=mu, scale=np.sqrt(mu))\n",
    "    N = stats.poisson(mu)\n",
    "    x = np.linspace(0, X.ppf(0.999))\n",
    "    n = np.arange(0, x[-1])\n",
    "\n",
    "    fig, ax = plt.subplots()\n",
    "    ax.plot(x, X.pdf(x), color='black', lw=2, label=\"Normal($\\mu=%d, \\sigma^2=%d$)\" % (mu, mu))\n",
    "    ax.bar(n, N.pmf(n), align='edge', label=r\"Poisson($\\lambda=%d$)\" % mu)\n",
    "    ax.set_ylim(0, X.pdf(x).max() * 1.25)\n",
    "    ax.legend(loc=2, ncol=2)\n",
    "    plt.close(fig)\n",
    "    return fig"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [],
   "source": [
    "from ipywidgets import interact\n",
    "import ipywidgets as widgets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD8CAYAAACMwORRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4wLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvqOYd8AAAIABJREFUeJzt3Xl4FGXa/v3v1Z19JQkBgYhBn4hCwg46ICCrQZDFcQRGBhlURgUXhFdQBkUecWWEB8UFxHVwV8RRZBMXMgoSViEGiRAkipCFhCRkz/3+kZhfgECa0Emlu6/PcfRhurq6+iyQs+9UV90txhiUUkq5F5vVAZRSSjmflrtSSrkhLXellHJDWu5KKeWGtNyVUsoNabkrpZQb0nJXSik3pOWulFJuSMtdKaXckJdVL9y0aVMTHR1t1csrpZRL2rp1a4YxJrK29Swr9+joaBITE616eaWUckkictCR9fSwjFJKuSEtd6WUckNa7kop5YYsO+Zek5KSEtLS0igsLLQ6ilLKYn5+fkRFReHt7W11FJfUqMo9LS2N4OBgoqOjERGr4yilLGKMITMzk7S0NNq0aWN1HJfUqA7LFBYWEhERocWulIcTESIiIvS3+PPQqMod0GJXSgHaBeer0ZW7Ukqp86flrpRSbkjLXSml3JCWuzpvH3/8MbfddhsjRoxg7dq1VsdRSqHlXiMRYdq0aVX358+fz5w5cxo0Q1BQUNXPBQUF9O3bl7KyMqe+xsSJE2nWrBmxsbHntZ2RI0eydOlSXnvtNd59912n5ikuLqZPnz6UlpaeV0alPE2jOs+9sfD19eWjjz7igQceoGnTpuf0XGMMxhhsNue9b77yyitcf/312O12p20TYMKECUyZMoXx48c7ZXuPPvookydPdmoeHx8fBgwYwLvvvstNN93kjJiniZ75mVO3l/rEUIfWs9vtxMXFUVpayuWXX87rr79OQEDAGdfv2bMn3377rbNi1qigoID4+Hg2bNiA3W7nhx9+YNiwYcycOZM77rijztudOHEin376Kc2aNWP37t1Vy4uLixk4cCAbNmzAy0vryJl05F4DLy8vJk2axIIFC0577JlnniE2NpbY2FgWLlwIQGpqKpdffjl33nknXbp0YePGjVx22WXceuutxMbGctNNN7F+/Xp69epFTEwM33//fdX2Ro4cSdeuXWnfvj1LliypMc/y5csZMWJE1f2rr76avXv3ApCZmVnnkXefPn0IDw93eP2dO3fSp08f2rVrh81mQ0R4+OGHMcYwY8YMhgwZQpcuXeqU5Wx5Ro4cyfLly+u83cbK39+fHTt2sHv3bnx8fHjxxRfPun59FzucPpCIi4vjnXfe4Y033jiv7U6YMIHVq1eftrz6m7dyLi33M5g8eTLLly8nJyenatnWrVt59dVX2bx5M5s2bWLp0qVs374dgL179zJ+/Hi2b9/ORRddREpKCvfccw+7du0iOTmZt956i4SEBObPn89jjz1Wtc1XXnmFrVu3kpiYyKJFi8jMzDwpR3FxMfv376f63PcpKSnExMQAsGvXL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PGeMy+AwuB+4Fyq4NYxABrRWRr5VX+DnG1cndomgPlvkQkCPgQuNcYc9zqPA3FGFNmjOlExRXiPUTEIw7Licgw4KgxZqvVWSzUyxjTBRgCTK48PFsrVyt3R6ZCUG6q8njzh8ByY8xHVuexgjEmG/gKiLc4SkPpBQyvPO78DtBfRP5tbaSGZYz5rfK/R4EVVByerpWrlbsjUyEoN1T5oeIy4EdjzDNW52lIIhIpIk0qf/YHBgLJ1qZqGMaYB4wxUcaYaCr+vW8wxoyzOFaDEZHAyhMIEJFAYDDg0NlyLlXuxphS4I+pEH4E3jPG7LE2VcMRkbeB74C2IpImIrdYnakB9QL+RsXIbUfl7VqrQzWQFsCXIrKLigHOOmOMx50S6KGaAwkishP4HvjMGLPakSe61KmQSimlHONSI3ellFKO0XJXSik3pOWulFJuSMtdKaXckJa7Ukq5IS13pZRyQ1ruSinlhrTclVLKDf3/D3hs/NZVKykAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "interact(f, mu=widgets.FloatSlider(min=1.0, max=20.0, step=1.0));"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Jupyter nbconvert"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[TerminalIPythonApp] WARNING | Subcommand `ipython nbconvert` is deprecated and will be removed in future versions.\n",
      "[TerminalIPythonApp] WARNING | You likely want to use `jupyter nbconvert` in the future\n",
      "[NbConvertApp] Converting notebook ch01-code-listing.ipynb to html\n",
      "[NbConvertApp] Writing 315769 bytes to ch01-code-listing.html\n"
     ]
    }
   ],
   "source": [
    "!ipython nbconvert --to html ch01-code-listing.ipynb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[TerminalIPythonApp] WARNING | Subcommand `ipython nbconvert` is deprecated and will be removed in future versions.\n",
      "[TerminalIPythonApp] WARNING | You likely want to use `jupyter nbconvert` in the future\n",
      "[NbConvertApp] Converting notebook ch01-code-listing.ipynb to pdf\n",
      "[NbConvertApp] Support files will be in ch01-code-listing_files/\n",
      "[NbConvertApp] Making directory ch01-code-listing_files\n",
      "[NbConvertApp] Writing 42308 bytes to notebook.tex\n",
      "[NbConvertApp] Building PDF\n",
      "[NbConvertApp] Running xelatex 3 times: ['xelatex', 'notebook.tex']\n",
      "[NbConvertApp] CRITICAL | xelatex failed: ['xelatex', 'notebook.tex']\n",
      "This is XeTeX, Version 3.14159265-2.6-0.99999 (TeX Live 2018) (preloaded format=xelatex)\n",
      " restricted \\write18 enabled.\n",
      "entering extended mode\n",
      "(./notebook.tex\n",
      "LaTeX2e <2018-04-01> patch level 2\n",
      "Babel <3.18> and hyphenation patterns for 84 language(s) loaded.\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/base/article.cls\n",
      "Document Class: article 2014/09/29 v1.4h Standard LaTeX document class\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/base/size11.clo))\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/base/fontenc.sty\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/base/t1enc.def)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/lm/t1lmr.fd))\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/psnfss/mathpazo.sty)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics/graphicx.sty\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics/keyval.sty)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics/graphics.sty\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics/trig.sty)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics-cfg/graphics.cfg)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics-def/xetex.def)))\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/caption/caption.sty\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/caption/caption3.sty))\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/adjustbox/adjustbox.sty\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/xkeyval/xkeyval.sty\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/generic/xkeyval/xkeyval.tex\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/generic/xkeyval/xkvutils.tex)))\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/adjustbox/adjcalc.sty)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/adjustbox/trimclip.sty\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/collectbox/collectbox.sty)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/adjustbox/tc-xetex.def))\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/ifoddpage/ifoddpage.sty)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/varwidth/varwidth.sty))\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/xcolor/xcolor.sty\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics-cfg/color.cfg))\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/tools/enumerate.sty)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/geometry/geometry.sty\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/ifpdf.sty)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/ifvtex.sty)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/generic/ifxetex/ifxetex.sty))\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/amsmath/amsmath.sty\n",
      "For additional information on amsmath, use the `?' option.\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/amsmath/amstext.sty\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/amsmath/amsgen.sty))\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/amsmath/amsbsy.sty)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/amsmath/amsopn.sty))\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/amsfonts/amssymb.sty\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/amsfonts/amsfonts.sty))\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/base/textcomp.sty\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/base/ts1enc.def))\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/upquote/upquote.sty)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/eurosym/eurosym.sty)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/ucs/ucs.sty\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/ucs/data/uni-global.def))\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/base/inputenc.sty\n",
      "\n",
      "Package inputenc Warning: inputenc package ignored with utf8 based engines.\n",
      "\n",
      ") (/usr/local/texlive/2018/texmf-dist/tex/latex/fancyvrb/fancyvrb.sty\n",
      "Style option: `fancyvrb' v2.7a, with DG/SPQR fixes, and firstline=lastline fix \n",
      "<2008/02/07> (tvz))\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/oberdiek/grffile.sty\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/oberdiek/kvoptions.sty\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/ltxcmds.sty)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/kvsetkeys.sty\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/infwarerr.sty)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/etexcmds.sty\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/ifluatex.sty))))\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/pdftexcmds.sty))\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/hyperref/hyperref.sty\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/hobsub-hyperref.sty\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/hobsub-generic.sty))\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/oberdiek/auxhook.sty)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/hyperref/pd1enc.def)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/latexconfig/hyperref.cfg)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/url/url.sty))\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/hyperref/hxetex.def\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/hyperref/puenc.def)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/stringenc.sty)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/oberdiek/rerunfilecheck.sty))\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/tools/longtable.sty)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/booktabs/booktabs.sty)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/enumitem/enumitem.sty)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/generic/ulem/ulem.sty)\n",
      "No file notebook.aux.\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/base/ts1cmr.fd)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/psnfss/t1ppl.fd)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/caption/ltcaption.sty)\n",
      "*geometry* driver: auto-detecting\n",
      "*geometry* detected driver: xetex\n",
      "*geometry* verbose mode - [ preamble ] result:\n",
      "* driver: xetex\n",
      "* paper: <default>\n",
      "* layout: <same size as paper>\n",
      "* layoutoffset:(h,v)=(0.0pt,0.0pt)\n",
      "* modes: \n",
      "* h-part:(L,W,R)=(72.26999pt, 469.75502pt, 72.26999pt)\n",
      "* v-part:(T,H,B)=(72.26999pt, 650.43001pt, 72.26999pt)\n",
      "* \\paperwidth=614.295pt\n",
      "* \\paperheight=794.96999pt\n",
      "* \\textwidth=469.75502pt\n",
      "* \\textheight=650.43001pt\n",
      "* \\oddsidemargin=0.0pt\n",
      "* \\evensidemargin=0.0pt\n",
      "* \\topmargin=-37.0pt\n",
      "* \\headheight=12.0pt\n",
      "* \\headsep=25.0pt\n",
      "* \\topskip=11.0pt\n",
      "* \\footskip=30.0pt\n",
      "* \\marginparwidth=59.0pt\n",
      "* \\marginparsep=10.0pt\n",
      "* \\columnsep=10.0pt\n",
      "* \\skip\\footins=10.0pt plus 4.0pt minus 2.0pt\n",
      "* \\hoffset=0.0pt\n",
      "* \\voffset=0.0pt\n",
      "* \\mag=1000\n",
      "* \\@twocolumnfalse\n",
      "* \\@twosidefalse\n",
      "* \\@mparswitchfalse\n",
      "* \\@reversemarginfalse\n",
      "* (1in=72.27pt=25.4mm, 1cm=28.453pt)\n",
      "\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/ucs/ucsencs.def)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/hyperref/nameref.sty\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/gettitlestring.sty))\n",
      "\n",
      "Package hyperref Warning: Rerun to get /PageLabels entry.\n",
      "\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/psnfss/ot1ppl.fd)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/psnfss/omlzplm.fd)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/psnfss/omszplm.fd)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/psnfss/omxzplm.fd)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/psnfss/ot1zplm.fd)\n",
      "\n",
      "LaTeX Warning: No \\author given.\n",
      "\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/se-ascii-print.def)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/lm/t1lmtt.fd)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/lm/ts1lmtt.fd) [1]\n",
      "! Text line contains an invalid character.\n",
      "l.431 ^^[\n",
      "         [0;31mDocstring:^^[[0m\n",
      "? \n",
      "! Emergency stop.\n",
      "l.431 ^^[\n",
      "         [0;31mDocstring:^^[[0m\n",
      "Output written on notebook.pdf (1 page).\n",
      "Transcript written on notebook.log.\n",
      "\n",
      "[NbConvertApp] PDF successfully created\n",
      "[NbConvertApp] Writing 16831 bytes to ch01-code-listing.pdf\n"
     ]
    }
   ],
   "source": [
    "!ipython nbconvert --to pdf ch01-code-listing.ipynb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Overwriting custom_template.tplx\n"
     ]
    }
   ],
   "source": [
    "%%writefile custom_template.tplx\n",
    "((*- extends 'article.tplx' -*))\n",
    "\n",
    "((* block title *)) \\title{Document title} ((* endblock title *))\n",
    "((* block author *)) \\author{Author's Name} ((* endblock author *))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[TerminalIPythonApp] WARNING | Subcommand `ipython nbconvert` is deprecated and will be removed in future versions.\n",
      "[TerminalIPythonApp] WARNING | You likely want to use `jupyter nbconvert` in the future\n",
      "[NbConvertApp] Converting notebook ch01-code-listing.ipynb to pdf\n",
      "[NbConvertApp] Support files will be in ch01-code-listing_files/\n",
      "[NbConvertApp] Making directory ch01-code-listing_files\n",
      "[NbConvertApp] Writing 42331 bytes to notebook.tex\n",
      "[NbConvertApp] Building PDF\n",
      "[NbConvertApp] Running xelatex 3 times: ['xelatex', 'notebook.tex']\n",
      "[NbConvertApp] CRITICAL | xelatex failed: ['xelatex', 'notebook.tex']\n",
      "This is XeTeX, Version 3.14159265-2.6-0.99999 (TeX Live 2018) (preloaded format=xelatex)\n",
      " restricted \\write18 enabled.\n",
      "entering extended mode\n",
      "(./notebook.tex\n",
      "LaTeX2e <2018-04-01> patch level 2\n",
      "Babel <3.18> and hyphenation patterns for 84 language(s) loaded.\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/base/article.cls\n",
      "Document Class: article 2014/09/29 v1.4h Standard LaTeX document class\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/base/size11.clo))\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/base/fontenc.sty\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/base/t1enc.def)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/lm/t1lmr.fd))\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/psnfss/mathpazo.sty)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics/graphicx.sty\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics/keyval.sty)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics/graphics.sty\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics/trig.sty)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics-cfg/graphics.cfg)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics-def/xetex.def)))\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/caption/caption.sty\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/caption/caption3.sty))\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/adjustbox/adjustbox.sty\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/xkeyval/xkeyval.sty\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/generic/xkeyval/xkeyval.tex\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/generic/xkeyval/xkvutils.tex)))\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/adjustbox/adjcalc.sty)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/adjustbox/trimclip.sty\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/collectbox/collectbox.sty)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/adjustbox/tc-xetex.def))\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/ifoddpage/ifoddpage.sty)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/varwidth/varwidth.sty))\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/xcolor/xcolor.sty\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics-cfg/color.cfg))\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/tools/enumerate.sty)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/geometry/geometry.sty\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/ifpdf.sty)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/ifvtex.sty)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/generic/ifxetex/ifxetex.sty))\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/amsmath/amsmath.sty\n",
      "For additional information on amsmath, use the `?' option.\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/amsmath/amstext.sty\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/amsmath/amsgen.sty))\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/amsmath/amsbsy.sty)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/amsmath/amsopn.sty))\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/amsfonts/amssymb.sty\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/amsfonts/amsfonts.sty))\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/base/textcomp.sty\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/base/ts1enc.def))\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/upquote/upquote.sty)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/eurosym/eurosym.sty)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/ucs/ucs.sty\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/ucs/data/uni-global.def))\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/base/inputenc.sty\n",
      "\n",
      "Package inputenc Warning: inputenc package ignored with utf8 based engines.\n",
      "\n",
      ") (/usr/local/texlive/2018/texmf-dist/tex/latex/fancyvrb/fancyvrb.sty\n",
      "Style option: `fancyvrb' v2.7a, with DG/SPQR fixes, and firstline=lastline fix \n",
      "<2008/02/07> (tvz))\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/oberdiek/grffile.sty\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/oberdiek/kvoptions.sty\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/ltxcmds.sty)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/kvsetkeys.sty\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/infwarerr.sty)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/etexcmds.sty\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/ifluatex.sty))))\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/pdftexcmds.sty))\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/hyperref/hyperref.sty\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/hobsub-hyperref.sty\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/hobsub-generic.sty))\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/oberdiek/auxhook.sty)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/hyperref/pd1enc.def)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/latexconfig/hyperref.cfg)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/url/url.sty))\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/hyperref/hxetex.def\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/hyperref/puenc.def)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/stringenc.sty)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/oberdiek/rerunfilecheck.sty))\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/tools/longtable.sty)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/booktabs/booktabs.sty)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/enumitem/enumitem.sty)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/generic/ulem/ulem.sty)\n",
      "No file notebook.aux.\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/base/ts1cmr.fd)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/psnfss/t1ppl.fd)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/caption/ltcaption.sty)\n",
      "*geometry* driver: auto-detecting\n",
      "*geometry* detected driver: xetex\n",
      "*geometry* verbose mode - [ preamble ] result:\n",
      "* driver: xetex\n",
      "* paper: <default>\n",
      "* layout: <same size as paper>\n",
      "* layoutoffset:(h,v)=(0.0pt,0.0pt)\n",
      "* modes: \n",
      "* h-part:(L,W,R)=(72.26999pt, 469.75502pt, 72.26999pt)\n",
      "* v-part:(T,H,B)=(72.26999pt, 650.43001pt, 72.26999pt)\n",
      "* \\paperwidth=614.295pt\n",
      "* \\paperheight=794.96999pt\n",
      "* \\textwidth=469.75502pt\n",
      "* \\textheight=650.43001pt\n",
      "* \\oddsidemargin=0.0pt\n",
      "* \\evensidemargin=0.0pt\n",
      "* \\topmargin=-37.0pt\n",
      "* \\headheight=12.0pt\n",
      "* \\headsep=25.0pt\n",
      "* \\topskip=11.0pt\n",
      "* \\footskip=30.0pt\n",
      "* \\marginparwidth=59.0pt\n",
      "* \\marginparsep=10.0pt\n",
      "* \\columnsep=10.0pt\n",
      "* \\skip\\footins=10.0pt plus 4.0pt minus 2.0pt\n",
      "* \\hoffset=0.0pt\n",
      "* \\voffset=0.0pt\n",
      "* \\mag=1000\n",
      "* \\@twocolumnfalse\n",
      "* \\@twosidefalse\n",
      "* \\@mparswitchfalse\n",
      "* \\@reversemarginfalse\n",
      "* (1in=72.27pt=25.4mm, 1cm=28.453pt)\n",
      "\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/ucs/ucsencs.def)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/hyperref/nameref.sty\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/gettitlestring.sty))\n",
      "\n",
      "Package hyperref Warning: Rerun to get /PageLabels entry.\n",
      "\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/psnfss/ot1ppl.fd)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/psnfss/omlzplm.fd)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/psnfss/omszplm.fd)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/psnfss/omxzplm.fd)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/psnfss/ot1zplm.fd)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/generic/oberdiek/se-ascii-print.def)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/lm/t1lmtt.fd)\n",
      "(/usr/local/texlive/2018/texmf-dist/tex/latex/lm/ts1lmtt.fd) [1]\n",
      "! Text line contains an invalid character.\n",
      "l.431 ^^[\n",
      "         [0;31mDocstring:^^[[0m\n",
      "? \n",
      "! Emergency stop.\n",
      "l.431 ^^[\n",
      "         [0;31mDocstring:^^[[0m\n",
      "Output written on notebook.pdf (1 page).\n",
      "Transcript written on notebook.log.\n",
      "\n",
      "[NbConvertApp] PDF successfully created\n",
      "[NbConvertApp] Writing 17066 bytes to ch01-code-listing.pdf\n"
     ]
    }
   ],
   "source": [
    "!ipython nbconvert ch01-code-listing.ipynb --to pdf --template custom_template.tplx"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[TerminalIPythonApp] WARNING | Subcommand `ipython nbconvert` is deprecated and will be removed in future versions.\n",
      "[TerminalIPythonApp] WARNING | You likely want to use `jupyter nbconvert` in the future\n",
      "[NbConvertApp] Converting notebook ch01-code-listing.ipynb to python\n",
      "[NbConvertApp] Writing 5081 bytes to ch01-code-listing.py\n"
     ]
    }
   ],
   "source": [
    "!ipython nbconvert ch01-code-listing.ipynb --to python"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Versions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table><tr><th>Software</th><th>Version</th></tr><tr><td>Python</td><td>3.6.6 64bit [GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)]</td></tr><tr><td>IPython</td><td>6.5.0</td></tr><tr><td>OS</td><td>Darwin 17.3.0 x86_64 i386 64bit</td></tr><tr><td>numpy</td><td>1.13.3</td></tr><tr><td colspan='2'>Tue Oct 02 06:08:48 2018 JST</td></tr></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{|l|l|}\\hline\n",
       "{\\bf Software} & {\\bf Version} \\\\ \\hline\\hline\n",
       "Python & 3.6.6 64bit [GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE\\_401/final)] \\\\ \\hline\n",
       "IPython & 6.5.0 \\\\ \\hline\n",
       "OS & Darwin 17.3.0 x86\\_64 i386 64bit \\\\ \\hline\n",
       "numpy & 1.13.3 \\\\ \\hline\n",
       "\\hline \\multicolumn{2}{|l|}{Tue Oct 02 06:08:48 2018 JST} \\\\ \\hline\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "Software versions\n",
       "Python 3.6.6 64bit [GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)]\n",
       "IPython 6.5.0\n",
       "OS Darwin 17.3.0 x86_64 i386 64bit\n",
       "numpy 1.13.3\n",
       "Tue Oct 02 06:08:48 2018 JST"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%reload_ext version_information\n",
    "%version_information numpy"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "py36",
   "language": "python",
   "name": "py36"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
